package com.lanxin.oa.zc.dao.daoImpl;

import com.lanxin.base.BaseDaoImpl;
import com.lanxin.bean.ZcAssetpurchaseapply;
import com.lanxin.bean.ZcAssetpurchaseapplydetails;
import com.lanxin.oa.zc.dao.ZcGouMaiDao;
import com.lanxin.util.PageBean;
import org.springframework.stereotype.Repository;

import java.util.Calendar;
import java.util.List;

@Repository
public class ZcGouMaiDaoImpl extends BaseDaoImpl implements ZcGouMaiDao {
    @Override
    public List<ZcAssetpurchaseapply> selectzcgm(Integer empid) {
        return super.queryAll("select distinct zcgm from ZcAssetpurchaseapply zcgm left join fetch zcgm.lcid left join fetch zcgm.empcj left join fetch zcgm.empsq left join fetch zcgm.dept left join fetch zcgm.zcgmmx where zcgm.creator="+empid+" ");
    }

    @Override
    public Integer getZcYdInfoCount() {
        Calendar car = Calendar.getInstance();

        String currentDate =String.valueOf(car.get(Calendar.YEAR))+"-"+String.valueOf(car.get(Calendar.MONTH)+1)+"-"+String.valueOf(car.get(Calendar.DATE));
        System.out.println(currentDate);
        String hql = "select count(*) from ZcAssetpurchaseapply  where date_format(createDate,'%Y-%m-%d') = str_to_date('"+currentDate+"','%Y-%m-%d')";

        Integer row = Integer.valueOf(selectByHQL(hql).toString());
        return row;
    }

    @Override
    public List selectflow() {
        return super.queryAll("from LcFlow");
    }

    @Override
    public List selectEmpByempName() {
        return super.queryAll("from ZzEmployee");
    }

    @Override
    public List selectDeptById() {
        return super.queryAll("from ZzDepartment");
    }

    @Override
    public List selectJobById() {
        return super.queryAll("from ZzJobinfo");
    }

    @Override
    public ZcAssetpurchaseapply selectByid(Integer oid) {
        return (ZcAssetpurchaseapply)super.selectByHQL("select distinct zcgm  from ZcAssetpurchaseapply zcgm left join fetch zcgm.zcgmmx where zcgm.oid="+oid+" ");
    }

    @Override
    public List<ZcAssetpurchaseapplydetails> selectmx(Integer oid) {
        return super.queryAll("from ZcAssetpurchaseapplydetails gmmx where gmmx.parentid="+oid);
    }

    @Override
    public PageBean<ZcAssetpurchaseapply> selectallzcgm(Integer page, Integer pageSize) {
        if(page==null){
            page=1;
        }
        if(pageSize==null){
            pageSize=5;
        }
        String hql="select distinct zcgm from ZcAssetpurchaseapply zcgm left join fetch zcgm.lcid left join fetch zcgm.empcj left join fetch zcgm.empsq left join fetch zcgm.dept left join fetch zcgm.zcgmmx where 1=1";
        return super.pageFenYE(hql,page,pageSize);
    }


}
